/**
 * User: Allen
 * Date: 12-4-18
 */
window.onload=function(){
    new PosIt($('container'));
    var btns=getByClass('pass');
    new LoginIn(btns,'hover')
    getByClass('login')[0].onmouseover=function(){
       css('add',this,'hovers')
    }
    getByClass('login')[0].onmouseout=function(){
        css('del',this,'hovers')
    }
    new MaskIt('regBtn','cloBtn','mask','dialog');
}


function MaskIt(regBtn,cloBtn,mask,dialog){
    this.regBtn=$(regBtn);
    this.cloBtn=$(cloBtn);
    this.mask=$(mask);
    this.dialog=$(dialog);
    var _this=this;
    this.regBtn.onclick=function(){
        _this.show();
    }
    this.cloBtn.onclick=function(){
        _this.hide();
    }
}
MaskIt.prototype={
    show:function(){
        this.mask.style.display='block';
        this.dialog.style.display='block';
        document.oncontextmenu=function(){
            return false;
        }
    },
    hide:function(){
        this.mask.style.display='none';
        this.dialog.style.display='none';
        document.oncontextmenu=function(){
            return true;
        }
    }
}
function PosIt(container){
    this.container=container;
    this.width=container.offsetWidth;
    this.height=container.offsetHeight;
    var _this=this;
    window.onresize=function(){
        _this.getWinsize();
    }
    this.getWinsize();
}
PosIt.prototype={
    getWinsize:function(){
        var wWidth=window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
        var wHeight=window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
        this.container.style.top=(wHeight-this.height)/2+'px';
        this.container.style.left=(wWidth-this.width)/2+'px';
    }
}
function  LoginIn(inputs,hoverClass){
    this.inputs=inputs;
    this.hoverClass=hoverClass;
    var _this=this;
    for(var i=0;i<this.inputs.length;i++){
        this.inputs[i].onfocus=function(){
            css('add',this.parentNode,_this.hoverClass);
        }
        this.inputs[i].onkeyup=function(){
            if(this.value){
                previousNode(this).style.display='none';
            }
            else{
                previousNode(this).style.display='';
            }
        }
        this.inputs[i].onblur=function(){
            css('del',this.parentNode,_this.hoverClass);
        }
        this.inputs[i].onpaste=function(){
            return false;
        }
    }
}
